package cn.pugle.base.collect;

import java.util.*;

/**
 * @author tzp
 * @since 2020/10/13
 */
public class MySortedListApp {
    public static void main(String[] args) {
//        List<Integer> list = new ArrayList<>();
        List<Integer> list = new LinkedList<>();
        for (int i = 0; i < 20; i++) {
            int a = (int) (Math.random() * 100);
            //用以下三行, 即可维护一个sorted list.
            int i1 = Collections.binarySearch(list, a);
            if (i1 < 0) i1 = -(i1 + 1);
            list.add(i1, a);
        }
        System.out.println(list);
    }
}
